<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Default_Model_Daily extends ZF_DB{
    protected $_table_name = "daily" ;
    
    protected $_madaily;
    protected $_masophu;
    protected $_madailycha;
    protected $_dsdailycon;
    protected $_maloaidaily;
    protected $_tendaily;
    protected $_ngaysinh;
    protected $_socmnd;
    protected $_sdt;
    protected $_diachi;
    protected $_ngaygianhap;
    protected $_capdaily;
    protected $_password;
    protected $_role;
    
    public function getMaDaiLy(){
        return $this->_madaily;
    }
    public function setMaDaiLy($madaily){
        $this->_madaily = $madaily;
    }
    public function getMaSoPhu(){
        return $this->_masophu;
    }
    public function setMaSoPhu($masophu){
        $this->_masophu = $masophu;
    }
    public function getMaDaiLyCha(){
        return $this->_madailycha;
        
    }
    public function setMaDaiLyCha($madailycha){
       $this->_madailycha = $madailycha;
        
    }
    public function getDsDaiLyCon(){
        return $this->_dsdailycon;
        
    }
    public function setDsDaiLyCon($dsdailycon){
        $this->_dsdailycon = $dsdailycon;
    }
    public function getMaLoaiDaiLy(){
        return $this->_maloaidaily;
    }
    public function setTenDaiLy($tendaily){
        $this->_tendaily = $tendaily;
    }
    public function getTenDaiLy(){
        return $this->_tendaily;
    }
    public function setNgaySinh($ngaysinh){
        $this->_ngaysinh = $ngaysinh;
    }
    public function getNgaySinh(){
        return $this->_ngaysinh;
        
    }
    public function setSoCMND($socmnd){
        $this->_socmnd = $socmnd;
    }
    public function getSoCMND(){
        return $this->_socmnd;
    }
    public function setSdt($sdt){
         $this->_sdt = $sdt;
     }
    public function getSdt(){
       return $this->_sdt;
   }
    public function getDiachi(){
        return $this->_diachi;
    }
    public function setDiachi($diachi){
        $this->_diachi = $diachi;
    }
    public function getNgayGiaNhap(){
        return $this->_ngaygianhap;
    }
    public function setNgayGiaNhap($ngaygianhap){
        $this->_ngaygianhap = $ngaygianhap;
    }
    public function getCapDaiLy(){
        return $this->_capdaily;
    }
    public function setCapDaiLy($capdaily){
        $this->_capdaily = $capdaily;
    }
    public function getPassword(){
        return $this->_password;
    }
    public function setPassword($password){
        $this->_password = $password;
    }
    public function getRole(){
        return $this->_role;
    }
    public function setRole($role){
        $this->_role = $role;
    }
    
    public function insert(
            $madaily, $madailycha, $maloaidaily, $tendaily, $ngaysinh, 
            $cmnd, $sdt, $diachi, $ngaygianhap, $capdaily, $masophu = 0, 
            $danhsachdailycon = "", $password = 0, $role = 0){
        
        if($madaily && $madailycha && $maloaidaily && $tendaily && $ngaysinh && $cmnd && $capdaily){             
                $data =  array(
                    'MaDaiLy'=>$madaily,
                    'MaSoPhu' =>$masophu,
                    'MaDaiLyCha'=>$madailycha,
                    'DSDaiLyCon'=>$danhsachdailycon,
                    'MaLoaiDaiLy'=>$maloaidaily,
                    'TenDaiLy'=>$tendaily,
                    'NgaySinh' =>$ngaysinh,
                    'SoCMND'=>$cmnd,
                    'Sdt'=>$sdt,
                    'DiaChi'=>$diachi,
                    'NgayGiaNhap'=>$ngaygianhap,
                    'CapDaiLy'=>$capdaily,
                    'Password'=>$password,
                    'Role'=>$role
                    );
            if ($this->db->insert($this->_table_name,$data) == 1)
            {
                return $this->db->lastInsertId();
            }
	}
        return -1;
	
    }
   
    public function update($madaily, $data){
        $where  = "MaDaiLy = " . $madaily;
	return $this->db->update(
                $this->_table_name,
                $data,$where);
    }
    public function getById($madaily){
        if($madaily)
	{
		$select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.MaDaiLy = ?",$madaily );
		
		$data = $this->db->fetchRow($select);
		if($data){
			$this->_madaily = $data['MaDaiLy'];
			$this->_masophu = $data['MaSoPhu'];
			$this->_madailycha = $data['MaDaiLyCha'];
			$this->_dsdailycon = $data['DSDaiLyCon'];
                        $this->_maloaidaily = $data['MaLoaiDaiLy'];       
                        $this->_tendaily = $data['TenDaiLy'];
                        $this->_ngaysinh = $data['NgaySinh'];
                        $this->_socmnd = $data['SoCMND'];
                        $this->_sdt = $data['Sdt'];
                        $this->_diachi = $data['DiaChi'];
                        $this->_ngaygianhap = $data['NgayGiaNhap'];
                        $this->_capdaily = $data['CapDaiLy'];
                        $this->_password = $data['Password'];
                        $this->_role = $data['Role'];
                }
                return $data;
	}
	return -1;
    }
   
    public function listAll(){
        $select = $this->db->select()
                ->from($this->_table_name);
        $data = $this->db->fetchAll($select);
	return $data;
    }
    
    public function getListAllDLCon($maDLCha){
        if($maDLCha){
            $select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.MaDaiLyCha = ?",$maDLCha );
            $data = $this->db->fetchAll($select);
            return $data;
        }
	return -1;
    }
    
    public function delete(){
            $this->getById($this->_id);
            $this->_active = 0;
            return $this->update();
    }
}
?>
